Fix for #277 (incorrect line/col number) #288
Open
+20
−12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix
lpegrex.calcline
to Correctly Compute Line and Column NumbersFunctionality Changes:
position
does not exceed the length ofsubject
by usingmath.min(position, #subject)
instead of anif
statement. This prevents potential out-of-bounds errors.colno
is0
, it now correctly assignsposition
as the column number, ensuring accurate reporting at line boundaries.lineend
by providing a fallback to#subject + 1
when a newline character is not found. This ensures the entire line is captured correctly, especially for the last line in thesubject
.Issue:
Fixes #277 - Incorrect line and line number for syntax error.
WARNING: Please, read this note carefully before submitting a new pull request:
Nelua is open source,
but not very open to contributions in the form of pull requests,
if you would like something fixed or implemented in the core language
try first submitting a bug report or opening a discussion instead of doing a PR.
The authors prefer it this way, so that the ideal solution is always provided,
without unwanted consequences on the project, thus keeping the quality of the software.
If you insist doing a PR, typically for a small bug fix, then follow these guidelines:
make test
.Motivation
Current version has a very subtle difference in the line number, so its more clear.
Code example
print(
Expected behavior